class Solution {
public:
    vector<int> getGoodIndices(vector<vector<int>>& vs, int tgt)
    {
        vector<int> ans;
        for (int i = 0; i < vs.size(); i++)
        {
            int a = vs[i][0];
            int b = vs[i][1];
            int c = vs[i][2];
            int d = vs[i][3];

            int isTgt = a;
            for (int j = 0; j < b - 1; j++)
            {
                isTgt *= a;
                isTgt %= 10;
            }
            isTgt %= 10;

            a = isTgt;
            for (int j = 0; j < c - 1; j++)
            {
                isTgt *= a;
                isTgt %= d;
            }
            isTgt %= d;


            if (isTgt == tgt) ans.push_back(i);
        }
        return ans;
    }
};